<?xml version="1.0" encoding="UTF-8"?>
<%@page contentType="text/html; charset=UTF-8"
		import="org.hibernate.Criteria,
				org.hibernate.criterion.Projections,
				java.util.HashMap" %>
<%
	Session hSession = HibernateUtil.getSessionFactory().getCurrentSession();
	Criteria crit;
	
	Class[] classes = {Book.class, Category.class, Author.class, User.class, Order.class};
	Map<Object, Object> counts = new HashMap<Object, Object>();
	
	for (Class critClass : classes) {
		crit = hSession.createCriteria(critClass);
		crit.setProjection(Projections.rowCount());
		counts.put(critClass, crit.uniqueResult());
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
	<title>Bookstore :: Back office</title>
	<%@include file="include.jsp" %>
</head>

<body>
	<%@include file="commun.jsp" %>
	
	<div class="contenuAvecMenu">
		<h2>Bienvenue dans le back office</h2>
		<p class="boite bleue">
			L'application contient actuellement:
			<br />
			- <strong><%= counts.get(Category.class) %></strong> categories,
			<br />
			- <strong><%= counts.get(Book.class) %></strong> livres,
			<br />
			- <strong><%= counts.get(Author.class) %></strong> auteurs,
			<br />
			- <strong><%= counts.get(User.class) %></strong> utilisateurs,
			<br />
			- <strong><%= counts.get(Order.class) %></strong> commandes.
			
		</p>
	</div>
</body>
</html>
